#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/4/22 20:18
# @Author : 闫峰
# @File    : check_attribute_value.py
import json
from decimal import Decimal
from urllib import parse

import jsonpath

from common.setting import ensure_path_sep
from utils.mysqlUtils.db_pool import Database
from utils.logging_tool.init_logger import init_logger
from utils.mysqlUtils.mongodb_utils import MongoDBLink
from utils.noticeUtils.dingtalkControl import DingTalkSendMsg
from utils.otherutils.MyThreadPool import MyThreadPool
from utils.otherutils.functions_control import convert_decimal_to_places

INFO, ERROR, WARNING = init_logger()
user = parse.quote_plus("admin")
passwd = parse.quote_plus("Zhcx@2023#MonDb")
web_logs_allegro_sync_modb = MongoDBLink(
    uri=f'mongodb://{user}:{passwd}@116.205.233.77:8807/?authSource=admin',
    dbname='walmart_api_table', coll_name='web_logs_allegro_sync')

class CheckAttributeValue:

    def test_main(self):
        zhcxkj_test_zentao_db = Database(ensure_path_sep("\\config\\shopeev2_config.yaml.bak"), "zhcxkj_test_zentao")
        db_java_test = Database(ensure_path_sep("\\config\\shopeev2_config.yaml.bak"), "test_jdw_database")
        get_task_id_list = f"""
        SELECT id FROM pms.zt_task WHERE 
        finishedDate >= '2024-06-01 00:00:00' AND openedBy in ('caijunwei','wangqian')
        """
        task_detail = {}
        for task_id in zhcxkj_test_zentao_db.fetch_all_tuple(get_task_id_list,()):
            task_id = task_id[0]
            get_task_info = f"""
            SELECT comment FROM pms.`zt_action`  WHERE objectID = %s
            """
            task_info = zhcxkj_test_zentao_db.fetch_all_tuple(get_task_info, (task_id,))
            task_info = list(filter(lambda x: x[0]!='' , task_info))
            task_detail[task_id] = task_info
            insert_sql = """
            REPLACE INTO monitor.deveop_task_details 
            (task_id,comment,create_time,update_time)
            VALUES (%s,%s,now(),now());
            """
            if task_info:
                rows = db_java_test.execute(insert_sql,(task_id,json.dumps(task_info)))
            else:
                rows = db_java_test.execute(insert_sql,(task_id,'',))

        print(f"执行完成,插入{len(task_detail)}")




if __name__ == '__main__':
    CheckAttributeValue().test_main()
